#
## Makefile for module.
#

CROSS		?= arm-none-eabi-
#CROSS		?= arm-linux-
NAME		:= led

#
# System environment variable.
#
ifneq (,$(findstring Linux, $(shell uname -s)))
HOSTOS		:= linux
endif
ifneq (,$(findstring windows, $(shell uname -s)))
HOSTOS		:= windows
endif
ifneq (,$(findstring MINGW, $(shell uname -s)))
HOSTOS		:= windows
endif
ifeq ($(strip $(HOSTOS)),)
$(error unable to determine host operation system from uname)
endif

#
# Load variables of flag.
#
ASFLAGS		:= -g -ggdb -Wall -O2
CFLAGS		:= -g -ggdb -Wall -O2
CXXFLAGS	:= -g -ggdb -Wall -O2
LDFLAGS		:= -T link.ld -nostdlib
ARFLAGS		:= -rcs
OCFLAGS		:= -v -O binary
ODFLAGS		:=
MCFLAGS		:= -mcpu=cortex-a8 -march=armv7-a

LIBDIRS		:=
LIBS		:=
INCDIRS		:=
SRCDIRS		:=

#
# Add necessary directory for INCDIRS and SRCDIRS.
#
INCDIRS		+= include
SRCDIRS		+= source

#
## You shouldn't need to change anything below this point.
#
AS			:= $(CROSS)gcc -x assembler-with-cpp
CC			:= $(CROSS)gcc
CXX			:= $(CROSS)g++
LD			:= $(CROSS)ld
AR			:= $(CROSS)ar
OC			:= $(CROSS)objcopy
OD			:= $(CROSS)objdump
MKDIR		:= mkdir -p
CP			:= cp -af
RM			:= rm -fr
CD			:= cd
FIND		:= find

ifeq ($(strip $(HOSTOS)), linux)
MKHEADER	:= ../tools/make_image/mkv210_image
endif
ifeq ($(strip $(HOSTOS)), windows)
MKHEADER	:= ../tools/windows/mkv210_image
endif


OBJDIRS		:= .obj
OUTPUTDIRS	:= output

all : $(NAME).bin

$(NAME).bin : $(NAME).o
	$(LD) -Ttext 0x0 -o $(NAME).elf $^
	$(OC) -O binary $(NAME).elf $(NAME).bin
	$(OD) -D $(NAME).elf > $(NAME)_elf.dis
	@echo make header information for irom booting
	@$(MKHEADER) $@

%.o : %.S
	@echo [CC] $^
	@$(CC) -o $@ $^ -c

%.o : %.c
	@echo [CC] $^
	@$(CC) -o $@ $^ -c

clean:
	$(RM) *.o *.elf *.bin *.dis *.sdCard $(OBJDIRS) $(OUTPUTDIRS)

.PHONY:clean all

#
# Include the dependency files, should be place the last of makefile
#
#sinclude $(shell $(MKDIR) $(OBJDIRS) $(OUTPUTDIRS))
